﻿using iemtm.WeChat.Core;
using iemtm.WeChat.Core.Managers;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace iemtm.WeChat.Web.Entry.Areas.Admin.Controllers
{
    /// <summary>
    /// 油机保养
    /// </summary>
    [Area("Admin")]
    [Route("/[controller]/[action]")]
    public class GenMainController : Controller
    {
        private readonly IGeneratorManager _generatorManager;
        private readonly IWorkManager _workManager;
        public GenMainController(IGeneratorManager generatorManager,
            IWorkManager workManager
            )
        {
            _generatorManager = generatorManager;
            _workManager = workManager;

        }
        /// <summary>
        /// 油机保养列表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 油机明细
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> Detail(string MaintId)
        {
            var MaintIdo =0;
            int.TryParse(MaintId,out MaintIdo);
            var model =await _generatorManager.GetGenMainAndPritureAsync(MaintIdo);
           
            return View(model);
        }


        /// <summary>
        /// 添加油机保养
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> AddGenMain(string dtuid)
        {

            //dtuid = "RJTX163218110554";
            //LoginInfo.PrjCode = "0113";
            Generator Gmodel = MemoryEntity.gBuffGen[dtuid];// GeneratorList.Frist(dtuId);
            double RunTime =await _generatorManager.GetGenMainRunTimeAsync(Gmodel.GensetNum, _workManager.CurrentUser.PrjCode); ;
            ViewBag.RunTime = RunTime;
            ViewBag.GensetNum = Gmodel.GensetNum;
            return View();
        }
    }
}
